package com.yqg.education.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yqg.education.controller.dto.UserPasswordDTO;
import com.yqg.education.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zxf
 * @since 2025-03-01
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where telephone = #{telephone} and password = #{password} and is_delete = 0")
    User getLoginUser(String telephone, String password);

    @Update("update user set password = #{newPass} where id = #{userId} and password = #{password} and is_delete = 0")
    int updatePassword(UserPasswordDTO userPasswordDTO);

    //重置密码————重置为默认密码123456
    @Update("update user set password = #{original_password},update_time = #{date} where id = #{id} and is_delete = 0")
    int resetPwd(@Param("id") int id, @Param("original_password") String password, @Param("date") Date date);

    List<User> findPage(Integer pageNum, Integer pageSize, String name, String telephone, Integer roleId, Integer classId);

    Long findCount(String name, String telephone, Integer roleId, Integer classId);

    @Select("select *,user_role.role_id from user left join user_role on user.id = user_role.user_id where role_id = 3 and is_delete = 0")
    List<User> selectTeachers();

    User stuFindUserInfo(@Param("stuId") Integer stuId);

    @Select("select *,user_role.role_id from user left join user_role on user.id = user_role.user_id where role_id = 2 and is_delete = 0")
    List<User> selectManages();

    Long getActiveStudentCount();

    Long getStudentCount(@Param("roleId") Integer roleId);

    List<User> exportStuData(String name, String telephone, Integer roleId, Integer classId);
}
